package com.example.module_home.Utils;

import android.annotation.SuppressLint;
import android.content.Context;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;

import com.blankj.utilcode.util.ScreenUtils;
import com.blankj.utilcode.util.SizeUtils;
import com.example.module_home.Module.CodeBank.CodeBankManager;
import com.example.module_home.R;
import com.timmy.tdialog.TDialog;
import com.timmy.tdialog.base.BindViewHolder;
import com.timmy.tdialog.listener.OnBindViewListener;
import com.timmy.tdialog.listener.OnViewClickListener;

/**
 * Created by Administrator on 2018/4/24 0024.
 */

public class DialogUtil {
    private static final String TAG = "DialogUtil";
    private Context mContext;
//    @SuppressLint("StaticFieldLeak")
//    private static volatile DialogUtil mInstance = null;
//    private DialogUtil(Context context) {
//        this.mContext=context;
//    }

//    public static DialogUtil getInstance(Context context) {
//        if (mInstance == null) {
//            synchronized (DialogUtil.class) {
//                if (mInstance == null) {
//                    mInstance = new DialogUtil(context);
//                }
//            }
//        }
//        return mInstance;
//    }
    public static TDialog showLoadingDialog(Context context){
        TDialog tDialog =  new TDialog.Builder(((FragmentActivity)context).getSupportFragmentManager())
                .setWidth(SizeUtils.dp2px(80))
                .setHeight(SizeUtils.dp2px(80))
                .setLayoutRes(R.layout.home_dialog_loading)
                .setCancelableOutside(true)
                .setCancelable(false)
                .create();
        return tDialog;
    }


    public static void showBackDialog(final FragmentActivity activity){
        new TDialog.Builder(activity.getSupportFragmentManager())
                .setLayoutRes(R.layout.home_dialog_back)
                .setScreenWidthAspect(activity,0.8f)
                .addOnClickListener(R.id.btn_back,R.id.btn_stay)
                .setOnViewClickListener(new OnViewClickListener() {
                    @Override
                    public void onViewClick(BindViewHolder viewHolder, View view, TDialog tDialog) {
                        if(view.getId()==R.id.btn_back) {
                            activity.finish();
                        }
                        tDialog.dismiss();
                    }
                }).create().show();
    }
}
